	capture log close
	set more off
	//cd -- Change working directory if you don't want to 
	*hardcode in the log and data locations
	


	//  program:	Replication file of motion to instruct results. 
	//  task:       replicate results, Summer 21
	//	project: 	Motions to Instruct
	//  author:     Josh Ryan \ Winter 2020-21
	// related files: voteleveldata_v2_050520.dta, billleveldata_v2_120420.dta

	// #Start
	// program setup


	*see variable labels
	
*from working directory
use "./Replication Data Upload/voteleveldata_forrap_v2_050520.dta", clear
describe

*FIGURE B1: HISTOGRAM OF VOTE PERCENTAGES IN FAVOR OF MOTION TO INSTRUCT

keep if motiontoinstruct==1

*i checked to ensure in pipc totalvotes equals totalyea+totalnay and it does

*drop if ties (there are none)
drop if motionper==.5

*106
tab motionper if motionper>.4 & motionper<.5

tab motionper if motionper<.5

*  Histogram of motionper variable 
twoway (histogram motionper if motionper < .50, freq bcolor(gray)) ///
(histogram motionper if motionper >=.50, freq bcolor(lightgray)),  ///
xlabel(0(.10)1, valuelabel)  xtitle(Percentage of House Voting for Motion to Instruct) scheme(s1mono)legend(off) xline(.5)


*TABLE B1: SUMMARY STATISTICS

use "./Replication Data Upload/voteleveldata_forrap_v2_050520.dta", clear
tab motiontoinstruct
tab pass
tab majpartyroll
sum totalyeaper
sum majpartyyeaper
sum minpartyyeaper

use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

*see variable descriptions for this data
describe
tab cong
tab motiontoinstruct
tab pass
tab majpartyroll

*TABLE B2: SUMMARY STATISTICS-MOTIONS TO INSTRUCT BY CONGRESS
tab cong motiontoinstruct, r

*TABLE C1: Logit Estimates of Minority Support on Motion to Instruct Offered and Passed for all Conference Bills

use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

eststo mioffer1: logit motiontoinstruct diff approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp, r
eststo mioffer2: logit motiontoinstruct diff approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r

use "./Replication Data Upload/voteleveldata_forrap_v2_050520.dta", clear

eststo mipass1: logit pass diff approp_nonauth mref mult HR_or_S artsize_ln  c.dw1##i.sponsorp, r
eststo mipass2: logit pass diff approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r

estout mioffer1 mioffer2 mipass1 mipass2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
diff "Difference in Majority and Minority Coalition Size in Favor" approp_nonauth "Appropriations Law" mref "Sponsor Member of Referral Committee" mult "Multiple Referral" HR_or_S "House or Senate Bill (Senate=1)" artsize_ln "Logged CQ Article Lines" ///
dw1 "Sponsor DW-NOMINATE Ideology Score" sponsorp "Sponsor Party (1=Republican)")


*TABLE C2: Logit Estimates of Overall Support on Motion to Instruct Offered and Passed for all Conference Bills

use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

eststo miofferoverall1: logit motiontoinstruct hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp, r
eststo miofferoverall2: logit motiontoinstruct hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r

use "./Replication Data Upload/voteleveldata_forrap_v2_050520.dta", clear

eststo mipassoverall1: logit pass hpassyeaper approp_nonauth mref mult HR_or_S  artsize_ln c.dw1##i.sponsorp, r
eststo mipassoverall2: logit pass hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r

estout miofferoverall1 miofferoverall2 mipassoverall1 mipassoverall2, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
hpassyeaper "Overall Chamber Percentage in Favor" approp_nonauth "Appropriations Law" mref "Sponsor Member of Referral Committee" mult "Multiple Referral" HR_or_S "House or Senate Bill (Senate=1)" artsize_ln "Logged CQ Article Lines" ///
dw1 "Sponsor DW-NOMINATE Ideology Score" sponsorp "Sponsor Party (1=Republican)")


*FIGURE 1: The Effect of Minority Party Support on the Probability a Motion to Instruct is Offered and Passed
use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

*Lef Panel 1
*from table "Logit Estimates of Minority Support on Motion to Instruct Offered and Passed for all Conference Bills", model 2
eststo mioffer2: logit motiontoinstruct diff approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r
eststo mioffer: margins, at(diff=(0 (.1) 1) approp_nonauth==0 mref==1 mult==1) post vsquish 

*margins are here:
use "./Replication Data Upload/motionstoinstruct_offer_logit.dta", clear

graph twoway (connected predprob perminparty, sort lcolor(black) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci perminparty, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci perminparty, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Motion to Instruct Offered)") xtitle("Difference in Majority and Minority"  "Coalition Size in Favor") ///
 ylabel(0(.2)1, valuelabel) ///
xlabel(0(.1)1, valuelabel) legend(col(1) order(1 "Predicted Probability" 2 "95% Confidence Interval") ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("DV: Motion to Instruct Offered")
graph save motiontoinstructoffered.gph, replace


*Right Panel 2
*From Table "Logit Estimates of Overall Support on Motion to Instruct Offered and Passed for all Conference Bills", model 2
use "./Replication Data Upload/voteleveldata_forrap_v2_050520.dta", clear


eststo mipass2: logit pass diff approp_nonauth mref mult HR_or_S artsize_ln c.dw1##i.sponsorp i.cong, r
margins, at(diff=(0 (.1) 1) approp_nonauth==0 mref==1 mult==1) post vsquish 

*margins are here:
use "./Replication Data Upload/motionstoinstruct_pass_logit.dta", clear

graph twoway (connected predprob perminparty, sort lcolor(black) lpattern(solid) lwidth(thin) msymbol(none) yaxis(1)) ///
(connected lci perminparty, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)) ///
(connected uci perminparty, sort lcolor(gray) lpattern(dash) lwidth(medium) msymbol(none)), ///
ytitle("Predicted Pr(Motion to Instruct Passage)") xtitle("Difference in Majority and Minority"  "Coalition Size in Favor") ///
 ylabel(0(.2)1, valuelabel) ///
xlabel(0(.1)1, valuelabel) legend(col(1) order(1 "Predicted Probability" 2 "95% Confidence Interval" ) ///
bplacement(nw) ring(1) size(small)) scheme(s1mono) graphregion(fcolor(white) ifcolor(white)) title("DV: Motion to Instruct Passage" "if Offered")
graph save motiontoinstructpass.gph, replace

graph combine motiontoinstructoffered.gph motiontoinstructpass.gph, scheme(s1mono) graphregion(fcolor(white) ifcolor(white))


*approval
use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

*keep if pass!=.
*keep if hconfpassyeaper!=.

*table of treated and not
table pass

gen passnomotion=0
replace passnomotion=1 if pass==0


*TABLE D1:  OLS Estimates of the Effect of a Failed Motion to Change in Percentage of Americans Approving of Congress
**ONLY 45, 60, 90 days shown in Table
**Other estimates shown in Figure D1
eststo approve1a: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<15 & timediff<15, r

eststo approve1b: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<30 & timediff<30, r

eststo approve1: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<45 & timediff<45, r

eststo approve2: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<60 & timediff<60, r

eststo approve2a: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<60 & timediff<75, r

eststo approve3: reg approvediff passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<90 & timediff<90, r

estout approve1 approve2 approve3, style(tex) cells(b(star fmt(2)) se(par)) starlevels($^\#$ .1 * 0.05) stats(aic N r2_p) varlabels( ///
passnomotion "Motion to Instruct Failed" hpassyeaper "Overall Chamber Percentage in Favor" approp_nonauth "Appropriations Law" mref "Sponsor Member of Referral Committee" mult "Multiple Referral" HR_or_S "House or Senate Bill (Senate=1)" artsize_ln "Logged CQ Article Lines" ///
dw1 "Sponsor DW-NOMINATE Ideology Score" sponsorp "Sponsor Party (1=Republican)" electionyear "Bill Enacted in Election Year" Percent_Change "Percent Change in Real Personal Income")



*Reverse Causality test
*Also shown in Figure D1
eststo approve1ap: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<15 & timediff_placebo>-15, r

eststo approve1bp: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<30 & timediff_placebo>-30, r

eststo approve1p: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<45 & timediff_placebo>-45, r

eststo approve2p: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<60 & timediff_placebo>-60, r

eststo approve2ap: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<75 & timediff_placebo>-75, r

eststo approve3p: reg approvediff_placebo passnomotion hpassyeaper approp_nonauth mref mult HR_or_S artsize_ln electionyear Percent_Change  c.dw1##i.sponsorp i.cong if timebetweenpolls<90 & timediff_placebo>-90, r

*See R file approval_coeff_graph_replication_v1_102221 for replication of graph

*Second placebo test--Placebo outcome test, pre-treatment
use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

*keep if pass!=.
*keep if hconfpassyeaper!=.

*table of treated and not
table pass

gen passnomotion=0
replace passnomotion=1 if pass==0

reg artsize_ln passnomotion hpassyeaper approp_nonauth mref mult HR_or_S  electionyear Percent_Change  c.dw1##i.sponsorp i.cong, r


*TABLE E1: Empirical Estimates of Successful Motions to Instruct on Conference Outcomes

use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear
mdesc
destring dw1, replace
destring sponsorparty, replace

gen hdiffpass=hconfpassyeaper-hpassyeaper
gen hdiffminpass=hconfpassminper-hpassminper 

eststo confpass1: reg hdiffpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r
eststo confpass2: reg hdiffpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp i.cong, r

eststo confpass3: reg hdiffminpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r
eststo confpass4: reg hdiffminpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp i.cong, r

estout confpass1 confpass2 confpass3 confpass4, style(tex) cells(b(star fmt(2)) se(par)) starlevels(* 0.05) stats(aic N r2) varlabels( ///
pass "Motion to Instruct Passed for Bill" hpassminper "Minority Party Percentage in Favor" hpassmajper "Minority Party Percentage in Favor" ///
minpartyyeaper "Minority Party Percentage in Favor of Motion to Instruct" majpartyyeaper "Majority Party Percentage in Favor of Motion to Instruct"  approp_nonauth "Appropriations Law" mref "Sponsor Member of Referral Committee" mult "Multiple Referral" HR_or_S "House or Senate Bill (Senate=1)" ///
dw1 "Sponsor DW-NOMINATE Ideology Score" sponsorp "Sponsor Party (1=Republican)")


*Table 1: Summary of Estimates of the Effect of a Passed Motion to Instruct on Conference Bills
*This table summarizes the various estimates from different estimation techniques, note that regression results are shown Table above.

use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

gen hdiffpass=hconfpassyeaper-hpassyeaper
gen hdiffminpass=hconfpassminper-hpassminper 


*regression results, also shown above:
reg hdiffpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp artsize_ln, r
reg hdiffpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp artsize_ln i.cong, r

reg hdiffminpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp artsize_ln, r
reg hdiffminpass pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp artsize_ln i.cong, r

*matching
use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

gen hdiffpass=hconfpassyeaper-hpassyeaper
gen hdiffminpass=hconfpassminper-hpassminper 

keep if pass!=.
keep if hconfpassyeaper!=.

*table of treated and not
table pass

*imbalance of variables
imb hpassmajper hpassminper approp_nonauth mref mult HR_or_S dw1 sponsorp artsize_ln, treatment(pass)
*automatic coarsening
cem hpassmajper hpassminper approp_nonauth mref mult HR_or_S dw1 sponsorp artsize_ln, treatment(pass)
*matching result--overall support
reg hdiffpass pass [iweight=cem_weights]

*matching result--minority party support
reg hdiffminpass pass [iweight=cem_weights]


*Coarsening. all I've done is stratified majority and minority support into not majority of the party or not, and dw score by party  
cem hpassmajper (.501) hpassminper (.501) approp_nonauth mref mult HR_or_S dw1 (0) sponsorp artsize_ln (0), treatment(pass)
*matching result--overall support
reg hdiffpass pass [iweight=cem_weights]

*matching result--minority party support
reg hdiffminpass pass [iweight=cem_weights]



*Replication code for legislation sent to conference/resolving differences but never reported out of conference/voted on
*Discussed in Footnote 6
use "./Replication Data Upload/billleveldata_forrap_v2_120420.dta", clear

gen finalresolve=1
replace finalresolve=0 if hconfpassyeaper==.
tab finalresolve

*regression results predicting whether never reported out of conference/voted on
logit finalresolve motiontoinstruct hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r
logit finalresolve pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r

reg finalresolve motiontoinstruct hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r
reg finalresolve pass hpassmajper hpassminper approp_nonauth mref mult HR_or_S c.dw1##i.sponsorp, r


